void solve()
{
  int n;
  cin >> n;
  
  vvi c(n + 1, vi(n + 1));
  rep(i, 2, n) {
    int x, y;
    cin >> x >> y;
    c[x][y] = 1;
  }

  vector<tuple<int, int, int>> ans;
  auto dfs = [&](auto &&dfs, int r) {
    if (r == 1) {
      return;
    }
    vi a(n + 1), b(n + 1);
    rep(i, 1, r) {
      rep(j, 1, r) {
        a[i] += c[i][j];
        b[j] += c[i][j]; 
      }
    }

    if (b[r]) {
      rep(i, 1, r) {
        if (!b[i]) {
          ans.pb({2, i, r});
          rep(j, 1, r) {
            swap(c[j][i], c[j][r]);
          }
          break;
        }
      }
    }
    if (!a[r]) {
      rep(i, 1, r) {
        if (a[i]) {
          ans.pb({1, i, r});
          rep(j, 1, r) {
            swap(c[i][j], c[r][j]);
          }
          break;
        }
      }
    }
    dfs(dfs, r - 1);
  };
  dfs(dfs, n);

  cout << sz(ans) << '\n';
  for (auto &[t, x, y]: ans) {
    cout << t << ' ' << x << ' ' << y << '\n';
  }
}